<template>
		<form class="form-horizontal control-margin-form" v-el:localform>
			<div class="box-body">
				<div class="row">
 					<div class="col-sm-6">
					  <form-input title="图片名称" name="name" left="3"></form-input>
					  <div class="divide col-sm-offset-3"></div>
						<form-group title="图片类型" left="3">
							<select class="form-control" name="mediaType">
								<option value="1">image</option>
							</select>
						</form-group>
						<div class="divide col-sm-offset-3"></div>
					</div>
					<div class="col-sm-6">
						<form-group title="选择附件" left="3">
							<file-upload v-ref:fileupload></file-upload>
						</form-group>
						<div class="divide col-sm-offset-3"></div>
						<form-input title="图片描述" name="dsc" left="3"></form-input>
						<div class="divide col-sm-offset-3"></div>
					</div>
				</div>
			</div>
			<!-- /.box-body -->
			<!-- /.box-footer -->
		</form>
</template>

<script>
	export default {
		methods: {
			async handle() {
				let valid = $(this.$els.localform).valid();
				if(valid) {
					this.submit().then(response => {
							this.$dispatch("setCoverArg",response)
					},error => {

					})
					return true;

				} else {
					return false;
				}
			},
			submit() {
				let formData = new FormData(this.$els.localform);
				let mchtId = localStorage.getItem('get_id');
				formData.append("mchtIdFlag", mchtId);
		    	formData.append("type", "image");	
				return new Promise((resolve, reject) => {
						this.$postFormData({
							url: "/api/v1" + projectName_Url + "/wechat/media/upLoadFImg.html",
							data: formData
						}).then(response=>{
							let message = {
								title: "操作提示",
								content: "操作成功"
							}
							Midway.alert(message);
							resolve(response);
						},error => {
							reject();
						});
				});
			}
		},
		ready() {
			let self = this;
			$(this.$els.localform).validate({
				rules: {
					picName: {
						required:true
					},
					file: {
						required: true
					}
				},
				messages: {
					picName: {
						required:"图片名称不能为空"
					},
					file: {
						required: "请选择附件"
					}
				},
				errorPlacement: function(error, element) {
						$(element).closest('.form-group').next().html(error)
				}
			});
		}
	}
</script>
